<?php

namespace app\command;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Output\OutputInterface;


class AutoShowRule extends Command
{
    protected static $defaultName = 'autoShow:rule';
    protected static $defaultDescription = 'AutoShowRule';

    /**
     * @return void
     */
    protected function configure()
    {
        $this->addArgument('name', InputArgument::OPTIONAL, 'Name description');
    }

    /**
     * @param InputInterface $input
     * @param OutputInterface $output
     * @return int
     */
    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $name = $input->getArgument('name');

        $rules = \plugin\admin\app\model\Rule::where('pid', 0)->orWhereNull('pid')->get()->toArray();

        $pids = array_column($rules, 'id');

        $this->show($pids);

        return self::SUCCESS;
    }

    protected function show($pids)
    {
        if (count($pids) > 0) {
            $rules = \plugin\admin\app\model\Rule::whereIn('pid', $pids)->get()->toArray();
            \plugin\admin\app\model\Rule::whereIn('pid', $pids)->update(['is_show' => 1]);
            $this->show(array_column($rules, 'id'));
        }

    }

}
